<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单信息</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
    <link rel="stylesheet" href="css/treeTable.css">
    <style>
        .layui-form-label{
            width: 130px;
        }
        .layui-input-block{
            margin-left: 160px;
        }
        .predictArriveTimediv,.predictArriveTimediv1,.predictDeliveryTimediv,.predictDeliveryTimediv1,.shopRemarksdiv,.shopRemarksdiv1,#selectTable,#selectTable1,.selectTablespan,.selectTable1span,.table_total,.table_total_count,.table1_total,.table1_total_count,.replace_order_box{
            display: none;
        }
        .table_total,.table1_total,.table_total_count,.table1_total_count{
            text-align: right;
        }
        .address{
            padding: 20px 0;
        }
        .receiveTelephone{
            color: #999999;
        }
        td[data-edit="text"]{
            padding: 0!important;
        }
        td[data-edit="text"] .table_edit_div{
            border: 1px solid #5FB878;
            box-shadow: 1px 1px 20px rgba(0, 0, 0, .15);
            background: #ffffff;
            min-height: 38px;
            line-height: 38px;
        }
        
        td[data-field="goodCount"]{
            padding: 0!important;
        }
        td[data-field="goodCount"] .layui-table-cell{
            height: unset;
            line-height: 40px;
            padding: 0;
        }
        td[data-field="goodCount"] input{
            border: 1px solid #f58843;
            box-shadow: 1px 1px 20px rgba(0, 0, 0, .15);
            background: #ffffff;
            min-height: 38px;
            line-height: 38px;
            width: calc(100% - 22px);
            padding: 0 10px;
        }

        /* 商品 */
        .goodsTable_box{
            position: relative;
            overflow: auto;
            margin-right: -1px;
            margin-bottom: -1px;
        }
        .tableAdd{
            cursor: pointer;
            margin-right: 10px;
        }
        .tableDel{
            cursor: pointer;
        }
        .goods_table_action_btn{
            font-weight: bold;
        }
        .goods_table_product_name_td,
        .goods_table_count_td{
            padding: 0!important;
        }
        .goods_table_main_img_td{
            padding: 0 15px!important;
        }
        .goods_table_product_name_td input,
        .goods_table_count_td input{
            border: 1px solid #f58843;
            /* box-shadow: 1px 1px 20px rgba(0, 0, 0, .15); */
            background: #ffffff;
            min-height: 36px;
            line-height: 36px;
            width: calc(100% - 22px);
            padding: 0 10px;
        }
        .goods_table_select_goods_list_box{
            position: absolute;
            border: 1px solid #d2d2d2;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0,0,0,.12);
            margin: 5px 0;
            border-radius: 2px;
            z-index: 66666666;
            width: 399px;
            display: none;
        }
        .goods_table_select_goods_list{
            overflow: auto;
            max-height: 250px;
        }
        .goods_table_select_goods_list_empty{
            text-align: center;
            color: #999999;
            padding: 0 10px;
            line-height: 36px;
            font-weight: 400;
        }
        .goods_table_select_goods_list_item{
            padding: 0 10px;
            line-height: 36px;
            font-weight: 400;
            white-space: nowrap;
            cursor: pointer;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .goods_table_select_goods_list_item:hover{
            background-color: #f2f2f2;
            -webkit-transition: .5s all;
            transition: .5s all;
        }
        .goods_table_select_goods_list_item.disabled{
            cursor: not-allowed;
            color: #cccccc;
        }
        .goods_table_select_goods_list_item.active{
            background-color: #f2f2f2;
        }
        .goods_table_product_name_cell{
            padding: 5px 16px;
        }
        .goods_table_cell{
            width: 100px;
        }
    </style>
</head>
<body>
    <div class="maincontainer" id="orderDetail">
        <blockquote class="layui-elem-quote">
            <span class="block_title"></span>
            <button type="button" class="layui-btn layui-btn-sm" style="float: right;margin-top: -4px;" onclick="onback()">返回</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" style="float: right;margin-top: -4px;margin-right: 10px" onclick="onExport()">导出</button>
        </blockquote>
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">餐饮总公司名称：</label>
                <div class="layui-form-mid layui-word-aux foodManagerName"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">食堂名称：</label>
                <div class="layui-form-mid layui-word-aux canteenName"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单编号：</label>
                <div class="layui-form-mid layui-word-aux shopOrderNo"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否改单：</label>
                <div class="layui-form-mid layui-word-aux updateStatus"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block table">
                    <span class="selectTablespan">改单前：</span>
                    <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
                    <div class="table_total_count">总数：</div>
                    <div class="table_total">合计：</div>
                    <span class="selectTable1span">改单后：</span>
                    <table class="layui-hide" id="selectTable1" lay-filter="selectTable1"></table>
                    <div class="table1_total_count">总数：</div>
                    <div class="table1_total">合计：</div>
                </div>
            </div>
            <div class="layui-form-item replace_order_box" style="margin-bottom: 0;">
                <label class="layui-form-label">添加商品：</label>
                <div class="layui-form-mid layui-word-aux">代下单</div>
            </div>
            <div class="layui-form-item replace_order_box" v-clock>
                <label class="layui-form-label"></label>
                <div class="layui-input-block goodsTable">
                    <div class="goodsTable_box">
                        <table class="layui-table" id="goodsTable" lay-filter="goodsTable">
                            <thead>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td>商品名称</td>
                                    <td>商品图片</td>
                                    <td>规格</td>
                                    <td>单位</td>
                                    <td>数量（可编辑）</td>
                                    <td>单价（可编辑）</td>
                                    <td>小计</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="(item, index) in tableData">
                                    <td style="width: 18px;"><div class="goods_table_cell" style="width: 18px;">{{index + 1}}</div></td>
                                    <td class="goods_table_action_btn" style="width: 50px;">
                                        <div class="goods_table_cell" style="width: 50px;">
                                            <i class="layui-icon layui-icon-addition tableAdd" @click="ontableAdd"></i>
                                            <i class="layui-icon layui-icon-subtraction tableDel" v-show="tableData.length>1" @click="ontableDel(index)"></i>
                                        </div>
                                    </td>
                                    <td class="goods_table_product_name_td" v-if="!item.price" style="width: 400px">
                                        <div class="goods_table_cell" style="width: 400px;">
                                            <input type="text" name="productName" placeholder="输入商品名称" autocomplete="off" v-model="item.productName" @input="onTableInput(index)" @focus="onTabelFocus(index)" @blur="onTableBlur()">
                                        </div>
                                    </td>
                                    <td v-else><div class="goods_table_cell" style="width: 400px;">{{item.productName}}</div></td>
                                    <td class="goods_table_main_img_td">
                                        <div class="goods_table_cell">
                                            <img v-if="item.mainImage" :src="TUrl+item.mainImage" alt="" width="50px" height="30px">
                                        </div>
                                    </td>
                                    <td><div class="goods_table_cell">{{item.skuName}}</div></td>
                                    <td><div class="goods_table_cell">{{item.unitName}}</div></td>
                                    <td class="goods_table_count_td" style="width: 200px;">
                                        <div class="goods_table_cell" style="width: 200px;">
                                            <input type='Number' oninput="if(value.length>6)value=value.slice(0,6)" v-model='item.count' @blur="onBlurFun(index)">
                                        </div>
                                    </td>
                                    <td class="goods_table_count_td" style="width: 200px;">
                                        <div class="goods_table_cell" style="width: 200px;">
                                            <input type='Number' oninput="if(value.length>6)value=value.slice(0,6)" v-model='item.price' @blur="onBlurPrice(index)">
                                        </div>
                                    </td>
                                    <td><div class="goods_table_cell">{{item.total}}</div></td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><div class="table_count_total">总数：<span style="color: #fbaf7e">0</span></div></td>
                                    <td></td>
                                    <td><div class="goods_table_total">合计：<span style="color: #fbaf7e">￥0.00</span></div></td>
                                </tr>
                            </tbody>
                        </table>

                    </div>
                    <div class="goods_table_select_goods_list_box layui-anim layui-anim-fadein">
                        <div class="goods_table_select_goods_list" v-if="chooseGoodsList.length>0">
                            <div :class="'goods_table_select_goods_list_item '+(goodsIdSet.indexOf(citem.goodId)==-1?'':'disabled')"
                                v-for="(citem, cindex) in chooseGoodsList"
                                @click="onClickTableRender(cindex)"
                                @mouseout="onListBlur(cindex)"
                            >{{citem.productName}}</div>
                        </div>
                        <div v-else class="goods_table_select_goods_list_empty">没有找到相关数据</div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnModifyDiv">
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">交货日期：</label>
                <div class="layui-form-mid layui-word-aux deliveryTime"></div>
            </div>
            <div class="layui-form-item predictDeliveryTimediv">
                <label class="layui-form-label">预计发货时间：</label>
                <div class="layui-form-mid layui-word-aux predictDeliveryTime"></div>
            </div>
            <div class="layui-form-item predictDeliveryTimediv1">
                <label class="layui-form-label"><span class="redtext marginRight">*</span>预计发货时间：</label>
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="predictDeliveryTime" placeholder="" autocomplete="off">
                </div>
            </div>
            <!-- <div class="layui-form-item predictArriveTimediv">
                <label class="layui-form-label">预计到达时间：</label>
                <div class="layui-form-mid layui-word-aux predictArriveTime"></div>
            </div>
            <div class="layui-form-item predictArriveTimediv1">
                <label class="layui-form-label"><span class="redtext marginRight">*</span>预计到达时间：</label>
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="predictArriveTime" placeholder="">
                </div>
            </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label">买家备注：</label>
                <div class="layui-form-mid layui-word-aux remarks"></div>
            </div>
            <div class="layui-form-item shopRemarksdiv">
                <label class="layui-form-label">卖家备注：</label>
                <div class="layui-form-mid layui-word-aux shopRemarks"></div>
            </div>
            <div class="layui-form-item shopRemarksdiv1">
                <label class="layui-form-label">卖家备注：</label>
                <div class="layui-input-block">
                    <textarea name="shopRemarks" placeholder="请输入卖家备注" class="layui-textarea" maxlength="140"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block address">
                    <div style="margin-bottom: 8px;">
                        <i class="layui-icon layui-icon-location"></i>
                        <span class="receiveUser"></span>
                        <span class="receiveTelephone"></span>
                    </div>
                    <div style="margin-left: 20px;">
                        <span>地址：</span>
                        <span class="receiveAddressInfo"></span>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnDiv">
            </div>
        </form>
    </div>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- <script type="text/javascript" src="plugins/layui/modules/treeTable.js?v2"></script> -->
<script src="js/vue.min.js"></script>
<script>
    new Vue({
        el: '#orderDetail',
        data: {
            TUrl: '',
            http: '',
            tableData: [{
                productName: '', // 商品名称
                mainImage: '', // 商品图片
                skuName: '', // 规格
                price: '', // 单价
                unitName: '', // 单位
                count: 1, // 数量（可编辑）
                total: 0, // 小计

            }],
            chooseGoodsList: [], // 可选择的商品列表
            goodsIdSet: [], // 选中的商品id集合
            goodsIdSetList: [''], // 选中的商品详情集合
            focusNum: null, // input[name=productName]选中第几行
            active: null, // 自动选中的商品列表

            canteenId: '', // 食堂id
        },
        mounted() {
            var _this = this
            layui.config({
                base: 'plugins/layui/modules/',
            }).use(['http', 'form', 'laydate', 'table', 'treeTable'], function() {
                var http = layui.http,
                    form = layui.form,
                    laydate = layui.laydate,
                    table = layui.table,
                    treeTable  = layui.treeTable;
                _this.TUrl = TUrl
                _this.http = http

                var type = http.getPid('type');
                var shopOrderNo = http.getPid('id')
                var supplierAcceptOrderParamsList,myDetail
                
                // 返回
                window.onback = function() {
                    if(type){
                        $(window.parent.document).find('.maincontainer').show()
                        $(window.parent.document).find('#my_iframe').hide()
                        window.parent.layui.table.reload('selectTable')
                    }else{
                        window.history.back()
                    }
                }

                // 导出订单详情
                window.onExport = function() {
                    let shopOrderNoArray = []
                    let authentication = localStorage.getItem('xi-can-supplier-authentication')
                    shopOrderNoArray.push(shopOrderNo)
                    window.open(TUrl+"supplier/admin/shop/order/export/order/list/batch?authentication="+authentication+"&shopOrderNoArray="+shopOrderNoArray.toString())
                }

                // 获取当前供应商信息
                http.checking(function(supplierInfo) {
                    init(supplierInfo) // 获取订单详情
                })

                // 获取代下单档口已下单的goodId
                function getStallGoodId(list) {
                    for(var i=0;i<list.length;i++){
                        for(var j=0;j<list[i].singleOrderInfoVoList.length;j++){
                            if(list[i].singleOrderInfoVoList[j].placeStallStatus == 1){
                                _this.goodsIdSet.push(list[i].singleOrderInfoVoList[j].goodId)
                            }
                        }
                    }
                }
                // 获取订单详情
                function init(supplierInfo){
                    http.get('supplier/admin/shop/order/findById',{
                        shopOrderNo: shopOrderNo
                    },function(res){
                        if(res.code == 200){
                            myDetail = res.data
                            _this.canteenId = res.data.canteenId
                            getCheckReplaceOrderSupplier(myDetail) // 判断当前供应商是否是食堂的代下单供应商
                            getStallGoodId(JSON.parse(JSON.stringify(res.data.canteenSingleOrderGroupWithGoodInfoVoList))) // 获取代下单档口已下单的goodId
                            var data = res.data
                            if(data.orderStatusVo.filterUpdateOrderStatus==4){// 接单
                                $('.block_title').html('接单'+(data.orderStatusVo.filterUpdateOrderStatus==3?' - 待付款':(data.orderStatusVo.filterUpdateOrderStatus==4?' - 待接单':(data.orderStatusVo.filterUpdateOrderStatus==5?' - 待发货':(data.orderStatusVo.filterUpdateOrderStatus==6?' - 待确认':(data.orderStatusVo.filterUpdateOrderStatus==8?' - 已发货':(data.orderStatusVo.filterUpdateOrderStatus==9?' - 已完成':(data.orderStatusVo.filterUpdateOrderStatus==10?' - 已取消':''))))))))
                                var html = ''
                                if(data.updateStatus == 0&&data.billType==2){
                                    $('.btnModifyDiv').html('<div class="layui-input-block"><button type="button" class="layui-btn orderModifyBtn">修改订单</button></div>')
                                    html += '<div class="layui-input-block">'
                                    
                                    if(supplierInfo.xicanSendStatus == 1){ // 是否鲜云链接单和发货 0是 1否
                                        html += '<button type="button" class="layui-btn orderBtn">接单</button>'
                                    }

                                    html += '<button type="button" class="layui-btn layui-btn-primary cancelBtn">取消订单</button></div>'
                                    
                                }else{
                                    html = '<div class="layui-input-block">'
                                    if(supplierInfo.xicanSendStatus == 1){ // 是否鲜云链接单和发货 0是 1否
                                        html += '<button type="button" class="layui-btn orderBtn">接单</button>'
                                    }
                                    html += '<button type="button" class="layui-btn layui-btn-primary cancelBtn">取消订单</button></div>'
                                }
                                $('.btnDiv').html(html)
                            }else if(data.orderStatusVo.filterUpdateOrderStatus==5){ // 发货
                                $('.block_title').html('发货'+(data.orderStatusVo.filterUpdateOrderStatus==3?' - 待付款':(data.orderStatusVo.filterUpdateOrderStatus==4?' - 待接单':(data.orderStatusVo.filterUpdateOrderStatus==5?' - 待发货':(data.orderStatusVo.filterUpdateOrderStatus==6?' - 待确认':(data.orderStatusVo.filterUpdateOrderStatus==8?' - 已发货':(data.orderStatusVo.filterUpdateOrderStatus==9?' - 已完成':(data.orderStatusVo.filterUpdateOrderStatus==10?' - 已取消':''))))))))
                                // if(data.orderStatusVo.updateStatus==0){
                                    var html = '<div class="layui-input-block">'
                                    if(supplierInfo.xicanSendStatus == 1){ // 是否鲜云链接单和发货 0是 1否
                                        html += '<button type="button" class="layui-btn sendBtn">发货</button>'
                                    }
                                    html += '<button type="button" class="layui-btn layui-btn-primary cancelBtn">取消订单</button></div>'
                                    $('.btnDiv').html(html)
                                // }
                            }else{
                                $('.block_title').html('订单详情'+(data.orderStatusVo.filterUpdateOrderStatus==3?' - 待付款':(data.orderStatusVo.filterUpdateOrderStatus==4?' - 待接单':(data.orderStatusVo.filterUpdateOrderStatus==5?' - 待发货':(data.orderStatusVo.filterUpdateOrderStatus==6?' - 待确认':(data.orderStatusVo.filterUpdateOrderStatus==8?' - 已发货':(data.orderStatusVo.filterUpdateOrderStatus==9?' - 已完成':(data.orderStatusVo.filterUpdateOrderStatus==10?' - 已取消':''))))))))
                            }
                            $('.foodManagerName').html(data.foodManagerName)
                            $('.canteenName').html(data.canteenName)
                            $('.shopOrderNo').html(data.shopOrderNo)
                            $('.updateStatus').html(data.orderStatusVo.updateStatus==1?'是':'否')
                            $('.deliveryTime').html(data.deliveryTime.split(' ')[0])
                            if(data.orderStatusVo.filterUpdateOrderStatus != 10){
                                // if(data.predictArriveTime){
                                //     $('.predictArriveTimediv').show()
                                //     $('.predictArriveTime').html(data.predictArriveTime)
                                // }else{
                                //     $('.predictArriveTimediv1').show()
                                //     laydate.render({
                                //         elem: '#predictArriveTime'
                                //         ,type: 'datetime'
                                //         ,theme: '#fbaf7e'
                                //         ,format: 'yyyy-MM-dd HH:mm'
                                //     });
                                // }
                                if(data.predictDeliveryTime){
                                    $('.predictDeliveryTimediv').show()
                                    $('.predictDeliveryTime').html(data.predictDeliveryTime.substring(0, data.predictDeliveryTime.length-3))
                                }else{
                                    $('.predictDeliveryTimediv1').show()
                                    var day3 = new Date();
                                    day3.setTime(day3.getTime()+24*60*60*1000);
                                    var min = ''
                                    min += day3.getFullYear() + '-' + (day3.getMonth()+1) + '-' + day3.getDate() + ' ' + day3.getHours() + ':' + day3.getMinutes()
                                    // // console.log(min)
                                    laydate.render({
                                        elem: '#predictDeliveryTime'
                                        ,type: 'datetime'
                                        ,theme: '#fbaf7e'
                                        ,format: 'yyyy-MM-dd HH:mm'
                                        ,min: min
                                    });
                                }
                                if(data.orderStatusVo.filterUpdateOrderStatus == 4||data.orderStatusVo.filterUpdateOrderStatus == 5){
                                    $('.shopRemarksdiv1').show()
                                    $('textarea[name=shopRemarks]').val(data.shopRemarks)
                                }else{
                                    $('.shopRemarksdiv').show()
                                    $('.shopRemarks').html(data.shopRemarks)
                                }

                            }
                            $('.remarks').html(data.remarks?data.remarks:'无')
                            $('.receiveUser').html(data.receiveUser)
                            $('.receiveTelephone').html(data.receiveTelephone)
                            $('.receiveAddressInfo').html(data.receiveAddressInfo)

                            // supplierAcceptOrderParamsList = data.singleOrderInfoVoList
                            supplierAcceptOrderParamsList = JSON.stringify(data.canteenSingleOrderGroupWithGoodInfoVoList)
                            supplierAcceptOrderParamsList = JSON.parse(supplierAcceptOrderParamsList)
                            if(data.updateStatus == 0){ // 未改单
                                if(data.billType==2&&data.orderStatusVo.filterUpdateOrderStatus==4){ // 可改单
                                    $('#selectTable').show()
                                    $('.table_total').show()
                                    $('.table_total_count').show()
                                    // http.table1({
                                    //     elem: '#selectTable',
                                    //     id: 'selectTable',
                                    //     cols: [[
                                    //         {field:'goodNo', title: '商品编号', align : 'center'},
                                    //         {field:'productName', title: '商品名称', align : 'center'},
                                    //         {field:'price', title: '单价（可编辑）', align : 'center', edit: 'Number',style:"border:2px solid #58b5e5"},
                                    //         {field:'goodCount', title: '数量（可编辑）', align : 'center', edit: 'Number',style:"border:2px solid #58b5e5"},
                                    //         {field:'stallName', title: '档口名称', align : 'center'}
                                    //     ]],
                                    //     data: data.singleOrderInfoVoList
                                    // })
                                    for(var i=0;i<supplierAcceptOrderParamsList.length;i++){
                                        supplierAcceptOrderParamsList[i].id = i
                                        supplierAcceptOrderParamsList[i].total = (supplierAcceptOrderParamsList[i].goodCount * supplierAcceptOrderParamsList[i].price).toFixed(2)
                                        for(var j=0;j<supplierAcceptOrderParamsList[i].singleOrderInfoVoList.length;j++){
                                            supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].id = i+'-'+j
                                            supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].pid = i
                                            supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].total = (supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].goodCount * supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].price).toFixed(2)
                                        }
                                    }
                                    var editorTable = treeTable.render({
                                        elem: '#selectTable',
                                        data: supplierAcceptOrderParamsList,
                                        tree: {
                                            iconIndex:1
                                        },
                                        id: 'selectTable',
                                        cols: [
                                            {type: 'numbers', title: '序号',width: 60},
                                            // {field:'goodNo', title: '商品编号', align : 'center'},
                                            {field:'productName', title: '商品名称', align : 'center',
                                                templet: function(d){
                                                    var html = ''
                                                    html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                                    return html
                                                }
                                            },
                                            {field:'skuName', title: '规格', align : 'center'},
                                            {field:'unitName', title: '单位', align : 'center',
                                                templet: function(d){
                                                    return d.unitName?d.unitName:d.unit
                                                }
                                            },
                                            {field:'price', title: '单价', align : 'center'},
                                            {field:'goodCount', title: '数量（可编辑）', align : 'center',
                                                templet: function(d) {
                                                    if(d.stallName){
                                                        return "<input type='Number' value='"+(d.goodCount?d.goodCount:'')+"' onblur=\"onBlurFun(this)\">"
                                                        // if(d.unitDecimalStatus === 1){ // 允许输入小数
                                                        //     return "<input onblur=\"onKeyFloat(this)\" onafterpaste=\"onKeyFloat(this)\" value='"+(d.goodCount?d.goodCount:'')+"'>"
                                                        // }else{  // 不允许输入小数
                                                        //     return "<input onblur=\"onkeyFun(this)\" onafterpaste=\"onkeyFun(this)\" value='"+(d.goodCount?d.goodCount:'')+"'>"
                                                        // }
                                                    }else{
                                                        return d.goodCount
                                                    }
                                                }
                                            },
                                            {field:'total', title: '小计', align : 'center'},
                                            {field:'stallName', title: '档口名称', align : 'center'},
                                            {field:'', title: '操作', align : 'center',
                                                templet: function (d) {
                                                    if(d.stallName){
                                                        return '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs tree_table_del_btn">删除</button>';
                                                    }else{
                                                        return ''
                                                    }
                                                }
                                            }
                                        ],
                                        style: 'margin-top:0;',
                                        tree: {
                                            id: 'id',
                                            pidName: 'pid',  // pid的字段名
                                            childName: 'singleOrderInfoVoList',  // children的字段名
                                        }
                                    })
                                    // 表格监听删除
                                    $(document).on('click', '.tree_table_del_btn', function() {
                                        var $tr = $(this).parent().parent().parent().parent()
                                        var index = $tr.attr('data-pid')
                                        var sindex = $tr.attr('data-id').split('-')[1]
                                        
                                        loop: //循环标记
                                        // 删除子订单列表
                                        for(var i=0;i<supplierAcceptOrderParamsList.length;i++){
                                            for(var j=0;j<supplierAcceptOrderParamsList[i].singleOrderInfoVoList.length;j++){
                                                if(supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].id == index+'-'+sindex){
                                                    supplierAcceptOrderParamsList[i].singleOrderInfoVoList.splice(j, 1);
                                                    
                                                    // 判断子订单列表空，则父订单删除
                                                    if(supplierAcceptOrderParamsList[i].singleOrderInfoVoList.length == 0){
                                                        supplierAcceptOrderParamsList.splice(i, 1)
                                                    }
                                                    break loop;//跳出双重循环 
                                                }
                                            }
                                        }
                                        $tr.remove()
                                        $('div[lay-filter=selectTable] tr[data-id='+index+']').remove()
                                        console.log(supplierAcceptOrderParamsList)
                                    })

                                    // 监听单元格编辑
                                    window.onBlurFun = function(e) {
                                        var $tr = $(e).parent().parent().parent().parent()
                                        var index = $tr.attr('data-pid')
                                        var sindex = $tr.attr('data-id').split('-')[1]
                                        var value = e.value

                                        var modifyData = '' // 要修改的数据
                                        loop: //循环标记
                                        for(var i=0;i<supplierAcceptOrderParamsList.length;i++){
                                            for(var j=0;j<supplierAcceptOrderParamsList[i].singleOrderInfoVoList.length;j++){
                                                if(supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j].id == index+'-'+sindex){
                                                    modifyData = supplierAcceptOrderParamsList[i].singleOrderInfoVoList[j]
                                                    break loop;//跳出双重循环 
                                                }
                                            }
                                        }
                                        if(modifyData.unitDecimalStatus == 1){ // 允许输入小数
                                            var reg = /^((0|[1-9]\d{0,})((\.[0-9]{1,2})?))$/;
                                            if(!reg.test(value)) {
                                                layer.msg('当前商品数量格式有误')
                                                value = data.canteenSingleOrderGroupWithGoodInfoVoList[index].singleOrderInfoVoList[sindex].goodCount
                                            }

                                        }else{ // 不允许输入小数
                                            var regex = /^(0|[1-9][0-9]*)$/;
                                            if(!regex.test(value)) {
                                                layer.msg('当前商品数量只能为整数')
                                                value = data.canteenSingleOrderGroupWithGoodInfoVoList[index].singleOrderInfoVoList[sindex].goodCount
                                            }
                                        }
                                        $(e).val(Number(value))
                                        // 修改列表数据
                                        modifyData.goodCount = Number(value) 
                                        // 修改表格数
                                        $tr.find('td[data-field=total] .ew-tree-tips').html(Number(value) * modifyData.price)
                                        // 重新计算合计
                                        allTotalFun() 
                                    }
                                    // 重新计算合计
                                    function allTotalFun() {
                                        var sum = 0, count = 0
                                        for(var p=0;p<supplierAcceptOrderParamsList.length;p++){
                                            for(var k=0;k<supplierAcceptOrderParamsList[p].singleOrderInfoVoList.length;k++){
                                                sum += supplierAcceptOrderParamsList[p].singleOrderInfoVoList[k].goodCount * supplierAcceptOrderParamsList[p].singleOrderInfoVoList[k].price
                                                count += supplierAcceptOrderParamsList[p].singleOrderInfoVoList[k].goodCount
                                            }
                                        }
                                        $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block;">'+count+'</span>')
                                        $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block">￥'+sum.toFixed(2)+'</span>')
                                    }
                                    //监听单元格编辑
                                    // treeTable.on('edit(selectTable)', function(obj){
                                    //     // console.log(obj)
                                    //     var index = $(obj.tr).attr('data-index')
                                    //     data.canteenSingleOrderGroupWithGoodInfoVoList[index][obj.field] = Number(obj.value)

                                    // });
                                    // var sum = 0
                                    // for(var p=0;p<data.singleOrderInfoVoList.length;p++){
                                    //     sum += data.singleOrderInfoVoList[p].price*data.singleOrderInfoVoList[p].goodCount
                                    // }
                                    $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block">'+data.goodCount+'</span>')
                                    $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block">￥'+data.orderTotalMoney.toFixed(2)+'</span>')
                                }else{ // 不可改单
                                    $('#selectTable').show()
                                    $('.table_total_count').show()
                                    $('.table_total').show()
                                    // http.table1({
                                    //     elem: '#selectTable',
                                    //     id: 'selectTable',
                                    //     cols: [[
                                    //         {field:'goodNo', title: '商品编号', align : 'center'},
                                    //         {field:'productName', title: '商品名称', align : 'center'},
                                    //         {field:'price', title: '单价', align : 'center'},
                                    //         {field:'goodCount', title: '数量', align : 'center'},
                                    //         {field:'stallName', title: '档口名称', align : 'center'}
                                    //     ]],
                                    //     data: data.singleOrderInfoVoList
                                    // })
                                    
                                    for(var i=0;i<data.canteenSingleOrderGroupWithGoodInfoVoList.length;i++){
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].id = i
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].total = (data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount * data.canteenSingleOrderGroupWithGoodInfoVoList[i].price).toFixed(2)
                                        for(var j=0;j<data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList.length;j++){
                                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].id = i+'-'+j
                                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].pid = i
                                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total = (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount * data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price).toFixed(2)
                                        }
                                    }
                                    treeTable.render({
                                        elem: '#selectTable',
                                        data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                                        tree: {
                                            iconIndex:1
                                        },
                                        id: 'selectTable',
                                        cols: [
                                            {type: 'numbers', title: '序号',width: 60},
                                            // {field:'goodNo', title: '商品编号', align : 'center'},
                                            {field:'productName', title: '商品名称', align : 'center',
                                                templet: function(d){
                                                    var html = ''
                                                    html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                                    return html
                                                }
                                            },
                                            {field:'skuName', title: '规格', align : 'center'},
                                            {field:'unitName', title: '单位', align : 'center',
                                                templet: function(d){
                                                    return d.unitName?d.unitName:d.unit
                                                }
                                            },
                                            {field:'price', title: '单价', align : 'center'},
                                            {field:'goodCount', title: '数量', align : 'center'},
                                            {field:'total', title: '小计', align : 'center'},
                                            {field:'stallName', title: '档口名称', align : 'center'}
                                        ],
                                        style: 'margin-top:0;',
                                        tree: {
                                            id: 'id',
                                            pidName: 'pid',  // pid的字段名
                                            childName: 'singleOrderInfoVoList',  // children的字段名
                                        }
                                    })
                                    // var sum = 0
                                    // for(var p=0;p<data.singleOrderInfoVoList.length;p++){
                                    //     sum += data.singleOrderInfoVoList[p].price*data.singleOrderInfoVoList[p].goodCount
                                    // }
                                    $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block">'+data.goodCount+'</span>')
                                    $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block">￥'+data.orderTotalMoney.toFixed(2)+'</span>')
                                }
                            }else{ // 已改单
                                $('#selectTable').show()
                                $('.selectTablespan').show()
                                $('#selectTable1').show()
                                $('.selectTable1span').show()
                                $('.table_total_count').show()
                                $('.table_total').show()
                                $('.table1_total_count').show()
                                $('.table1_total').show()
                                // http.table1({
                                //     elem: '#selectTable',
                                //     id: 'selectTable',
                                //     cols: [[
                                //         {field:'goodNo', title: '商品编号', align : 'center'},
                                //         {field:'productName', title: '商品名称', align : 'center'},
                                //         {field:'originalGoodPrice', title: '单价', align : 'center',
                                //             templet: function(d){
                                //                 return d.originalGoodPrice?d.originalGoodPrice:d.price
                                //             }
                                //         },
                                //         {field:'originalGoodCount', title: '数量', align : 'center',
                                //             templet: function(d){
                                //                 return d.originalGoodCount?d.originalGoodCount:d.goodCount
                                //             }
                                //         },
                                //         {field:'stallName', title: '档口名称', align : 'center'}
                                //     ]],
                                //     data: data.singleOrderInfoVoList
                                // })
                                
                                var count = 0
                                for(var i=0;i<data.canteenSingleOrderGroupWithGoodInfoVoList.length;i++){
                                    data.canteenSingleOrderGroupWithGoodInfoVoList[i].id = i
                                    data.canteenSingleOrderGroupWithGoodInfoVoList[i].total = ((data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodPrice?data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodPrice:data.canteenSingleOrderGroupWithGoodInfoVoList[i].price)).toFixed(2)
                                    data.canteenSingleOrderGroupWithGoodInfoVoList[i].total1 = (((data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount||data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount===0)?data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].price)).toFixed(2)
                                    for(var j=0;j<data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList.length;j++){
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].id = i+'-'+j
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].pid = i
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total = ((data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodPrice?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodPrice:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price)).toFixed(2)
                                        
                                        data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total1 = (((data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount||data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount===0)?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price)).toFixed(2)

                                        count += data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount
                                    }
                                }
                                treeTable.render({
                                    elem: '#selectTable',
                                    data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                                    tree: {
                                        iconIndex:1
                                    },
                                    id: 'selectTable',
                                    cols: [
                                        {type: 'numbers', title: '序号',width: 60},
                                        // {field:'goodNo', title: '商品编号', align : 'center'},
                                        {field:'productName', title: '商品名称', align : 'center',
                                            templet: function(d){
                                                var html = ''
                                                html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                                return html
                                            }
                                        },
                                        {field:'skuName', title: '规格', align : 'center'},
                                        {field:'unitName', title: '单位', align : 'center',
                                            templet: function(d){
                                                return d.unitName?d.unitName:d.unit
                                            }
                                        },
                                        {field:'originalGoodPrice', title: '单价', align : 'center',
                                            templet: function(d){
                                                return d.originalGoodPrice?d.originalGoodPrice:d.price
                                            }
                                        },
                                        {field:'originalGoodCount', title: '数量', align : 'center',
                                            templet: function(d){
                                                return d.originalGoodCount?d.originalGoodCount:d.goodCount
                                            }
                                        },
                                        {field:'total', title: '小计', align : 'center'},
                                        {field:'stallName', title: '档口名称', align : 'center'}
                                    ],
                                    style: 'margin-top:0;',
                                    tree: {
                                        id: 'id',
                                        pidName: 'pid',  // pid的字段名
                                        childName: 'singleOrderInfoVoList',  // children的字段名
                                    }
                                })
                                // var sum = 0
                                // for(var p=0;p<data.singleOrderInfoVoList.length;p++){
                                //     sum += (data.singleOrderInfoVoList[p].originalGoodPrice?data.singleOrderInfoVoList[p].originalGoodPrice:data.singleOrderInfoVoList[p].price)*(data.singleOrderInfoVoList[p].originalGoodCount?data.singleOrderInfoVoList[p].originalGoodCount:data.singleOrderInfoVoList[p].goodCount)
                                // }
                                $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block">'+count+'</span>')
                                $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block">￥'+data.originalOrderAmount.toFixed(2)+'</span>')
                                // http.table1({
                                //     elem: '#selectTable1',
                                //     id: 'selectTable1',
                                //     cols: [[
                                //         {field:'goodNo', title: '商品编号', align : 'center'},
                                //         {field:'productName', title: '商品名称', align : 'center'},
                                //         {field:'price', title: '单价', align : 'center'},
                                //         {field:'goodCount', title: '数量', align : 'center'},
                                //         {field:'stallName', title: '档口名称', align : 'center'}
                                //     ]],
                                //     data: data.singleOrderInfoVoList
                                // })
                                
                                treeTable.render({
                                    elem: '#selectTable1',
                                    data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                                    tree: {
                                        iconIndex:1
                                    },
                                    id: 'selectTable1',
                                    cols: [
                                        {type: 'numbers', title: '序号',width: 60},
                                        // {field:'goodNo', title: '商品编号', align : 'center'},
                                        {field:'productName', title: '商品名称', align : 'center',
                                            templet: function(d){
                                                var html = ''
                                                html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                                return html
                                            }
                                        },
                                        {field:'skuName', title: '规格', align : 'center'},
                                        {field:'unitName', title: '单位', align : 'center',
                                            templet: function(d){
                                                return d.unitName?d.unitName:d.unit
                                            }
                                        },
                                        {field:'price', title: '单价', align : 'center'},
                                        {field:'refreshGoodCount', title: '数量', align : 'center',
                                            templet: function(d){
                                                return (d.refreshGoodCount||d.refreshGoodCount===0)?d.refreshGoodCount:d.goodCount
                                            }
                                        },
                                        {field:'total1', title: '小计', align : 'center'},
                                        {field:'stallName', title: '档口名称', align : 'center'}
                                    ],
                                    style: 'margin-top:0;',
                                    tree: {
                                        id: 'id',
                                        pidName: 'pid',  // pid的字段名
                                        childName: 'singleOrderInfoVoList',  // children的字段名
                                    }
                                })
                                // var sum1 = 0
                                // for(var q=0;q<data.singleOrderInfoVoList.length;q++){
                                //     sum1 += data.singleOrderInfoVoList[q].price*data.singleOrderInfoVoList[q].goodCount
                                // }
                                $('.table1_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block">'+data.goodCount+'</span>')
                                $('.table1_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block">￥'+data.orderTotalMoney.toFixed(2)+'</span>')
                            }
                            
                            // 监听表格事件
                            treeTable.on('tool(selectTable)', function(obj){
                                var data = obj.data;
                                if(obj.event == 'detail'){
                                    location.href="productManagementDetail.html?id="+data.productId
                                }
                            });
                        }else{
                            layer.msg(res.msg)
                        }
                    })
                }

                // 判断当前供应商是否是食堂的代下单供应商
                function getCheckReplaceOrderSupplier(data){
                    http.post('supplier/admin/canteen/checkReplaceOrderSupplier',{
                        canteenId: _this.canteenId
                    },function(res){
                        if(res.code == 200){
                            if(res.data == 1){ // 可代下单
                                if(data.orderStatusVo.filterUpdateOrderStatus==4&&data.updateStatus == 0&&data.billType==2){
                                    $('.replace_order_box').show()
                                }
                            }
                        }else{
                            layer.msg(res.msg)
                        }
                    })
                }

                // 修改订单
                $(document).on('click','.orderModifyBtn',function(){
                    var params = {
                        goodList: [],
                        shopOrderNo: shopOrderNo
                    }
                    
                    var oldData = []
                    for(var iold of myDetail.canteenSingleOrderGroupWithGoodInfoVoList){
                        for(var jold of iold.singleOrderInfoVoList){
                            oldData.push(jold.goodCount)
                        }
                    }
                    var newData = []
                    for(var inew of supplierAcceptOrderParamsList){
                        for(var jnew of inew.singleOrderInfoVoList){
                            newData.push(jnew.goodCount)
                        }
                    }
                    // 订单添加商品（代下单）
                    for(var i=0;i<_this.goodsIdSetList.length;i++){
                        if(_this.goodsIdSetList[i]){
                            params.goodList.push({
                                goodId: _this.goodsIdSetList[i].goodId, // 商品id
                                goodCount: Number(_this.goodsIdSetList[i].count), // 数量
                                goodPrice: Number(_this.goodsIdSetList[i].modifyprice) // 单价
                            })
                        }
                    } 
                    if(JSON.stringify(oldData) != JSON.stringify(newData) || params.goodList.length >0){
                        // 订单原有的商品列表
                        for(var i of supplierAcceptOrderParamsList){
                            for(var j of i.singleOrderInfoVoList){
                                if(Number(j.goodCount) > 0 || Number(j.goodCount) == 0) { // 有商品数量
                                    params.goodList.push({
                                        goodId: j.goodId, // 商品id
                                        goodCount: Number(j.goodCount), // 数量
                                        goodPrice: Number(j.price), // 单价
                                        stallId: j.stallId // 档口
                                    })
                                }
                            }
                        }

                    }else{
                        layer.msg('未修改信息');
                        return
                    }

                    console.log(params)

                    http.postJSON('supplier/admin/shop/order/updateOrderInfo/v2',JSON.stringify(params),function(res){
                        if(res.code == 200){
                            layer.msg('操作成功')
                            setTimeout(function(){
                                // window.history.back()
                                onback()
                            },500)
                        }else{
                            layer.msg(res.msg)
                        }
                    })
                })
                    
                // 接单
                $(document).on('click','.orderBtn',function(){
                    var predictDeliveryTime = $('#predictDeliveryTime').val()
                    // var predictArriveTime = $('#predictArriveTime').val()
                    var shopRemarks = $('textarea[name=shopRemarks]').val()
                    if(!predictDeliveryTime){
                        layer.msg('请选择预计发货时间')
                        return
                    }
                    // if(!predictArriveTime){
                    //     layer.msg('请选择预计到达时间')
                    //     return
                    // }
                    var arr = []
                    if(myDetail.updateStatus == 0){
                        if(JSON.stringify(myDetail.canteenSingleOrderGroupWithGoodInfoVoList) != JSON.stringify(supplierAcceptOrderParamsList)){
                            for(var i=0;i<supplierAcceptOrderParamsList.length;i++){
                                var a = {
                                    "goodCount": Number(supplierAcceptOrderParamsList[i].goodCount),
                                    "goodId": supplierAcceptOrderParamsList[i].goodId,
                                    "goodPrice": Number(supplierAcceptOrderParamsList[i].price),
                                    "shopOrderNo": shopOrderNo
                                }
                                arr.push(a)
                            }

                        }

                    }
                    http.postJSON('supplier/admin/shop/order/accept',JSON.stringify({
                        // "predictArriveTime": predictArriveTime+":00",
                        "predictDeliveryTime": predictDeliveryTime+":00",
                        "shopOrderNo": shopOrderNo,
                        "shopRemarks": shopRemarks,
                        "supplierAcceptOrderParamsList": arr
                    }),function(res){
                        if(res.code == 200){
                            layer.msg('操作成功')
                            setTimeout(function(){
                                // window.history.back()
                                onback()
                            },500)
                        }else{
                            layer.msg(res.msg)
                        }
                    })
                })

                // 取消订单
                $(document).on('click','.cancelBtn',function(){
                    http.myOpen({
                        title:'提示',
                        content:'<p style="text-align:center;margin-top:20px">是否已和买家取得联系并取消订单！</p>',
                        area:['300px','150px'],
                        btn:['确定','取消'],
                        btn1:function(index, layero){
                            http.post('supplier/admin/shop/order/cancel',{
                                "shopOrderNo": shopOrderNo,
                            },function(res){
                                if(res.code == 200){
                                    layer.close(index)
                                    layer.msg('操作成功')
                                    setTimeout(function(){
                                        // window.history.back()
                                        onback()
                                    },500)
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                        }
                    })
                })

                // 发货
                $(document).on('click','.sendBtn',function(){
                    var shopRemarks = $('textarea[name=shopRemarks]').val()
                    http.post('supplier/admin/shop/order/send',{
                        "shopOrderNo": shopOrderNo,
                        "shopRemarks": shopRemarks,
                    },function(res){
                        if(res.code == 200){
                            layer.msg('操作成功')
                            setTimeout(function(){
                                // window.history.back()
                                onback()
                            },500)
                        }else{
                            layer.msg(res.msg)
                        }
                    })
                })
                
            })
        },
        methods: {
            // 模糊查询商品列表
            getGoodsListMore(productName){
                console.log(productName)
                if (!this.canteenId){
                    layer.msg('请选择食堂')
                    return
                }
                var _this = this
                this.http.get('supplier/admin/product/supplierListGoods',{
                    canteenId: this.canteenId,
                    productName: productName,
                    page: 1,
                    limit: 20
                }, function(res){
                    if(res.code == 200){
                        _this.chooseGoodsList = res.data.list
                        
                        for(var i=0;i<_this.chooseGoodsList.length;i++){
                            if(_this.goodsIdSet.indexOf(_this.chooseGoodsList[i].goodId)==-1){ // 可选
                                $('.goods_table_select_goods_list_item').eq(i).addClass('active')
                                _this.active = i
                                break
                            }
                        }
                    }else{
                        layer.msg(res.msg)
                    }
                })
            },
            // 添加一条
            ontableAdd() {
                this.tableData.push({
                    productName: '', // 商品名称
                    mainImage: '', // 商品图片
                    skuName: '', // 规格
                    price: '', // 单价
                    unitName: '', // 单位
                    count: 1, // 数量（可编辑）
                    total: 0, // 小计
                })
                this.goodsIdSetList.push('')
            },
            // 删除一条
            ontableDel(index){
                this.tableData.splice(index, 1)
                if(this.goodsIdSetList.length > index){
                    if(this.goodsIdSetList[index]) {
                        var delGoodsId = this.goodsIdSetList[index].goodId
                        var delIndex = this.goodsIdSet.indexOf(delGoodsId)
                        if(delIndex != -1) {
                            this.goodsIdSet.splice(delIndex, 1)
                        }
                    }
                    this.goodsIdSetList.splice(index, 1)
                }
                this.getTotal() // 计算合计
            },
            // 光标进入到input
            onTabelFocus(index) {
                var _this = this
                var $el = $('#goodsTable tbody tr').eq(index).find('input[name=productName]')
                this.getGoodsListMore($el.val()) // 查询商品列表
                setTimeout(function(){
                    $('.goods_table_select_goods_list_box').show()
                    var position = $el.parent().parent().position()
                    _this.focusNum = index
                    // console.log(position)
                    $('.goods_table_select_goods_list_box').css("top", position.top+38)
                    $('.goods_table_select_goods_list_box').css("left", position.left)
                    
					$(document).on('keydown', _this.enterConfirm); //监听键盘事件
			
                },500)
            },
            // 光标离开input
            onTableBlur() {
                var _this = this
                $(document).off('keydown', _this.enterConfirm); //解除键盘事件
                setTimeout(function(){
                    $('.goods_table_select_goods_list_box').hide()
                },300)
            },
            enterConfirm(event){
                console.log(event.keyCode)
                if(event.keyCode === 13){ // enter
                    this.onClickTableRender(this.active)
                }else if(event.keyCode === 40){ // down
                    if(this.active < this.chooseGoodsList.length-1){
                        var active = this.downpSelectActive(this.active) // 键盘向下判断可选项
                        if(active == this.active){
                            return
                        }
                        $(".goods_table_select_goods_list").animate({scrollTop:active*36},100);
                        $('.goods_table_select_goods_list_item').eq(this.active).removeClass('active')
                        $('.goods_table_select_goods_list_item').eq(active).addClass('active')
                        this.active = active

                    }
                }else if(event.keyCode === 38){ // up
                    if(this.active !== 0){
                        var active = this.upSelectActive(this.active) // 键盘向上判断可选项
                        if(active == this.active){
                            return
                        }
                        $(".goods_table_select_goods_list").animate({scrollTop:active*36},100);
                        $('.goods_table_select_goods_list_item').eq(this.active).removeClass('active')
                        $('.goods_table_select_goods_list_item').eq(active).addClass('active')
                        this.active = active

                    }
                }
            },
            // 键盘向下判断可选项
            downpSelectActive(index) {
                for(var i=index+1;i<this.chooseGoodsList.length;i++){
                    if(this.goodsIdSet.indexOf(this.chooseGoodsList[i].goodId)==-1){ // 可选
                        return i
                    }
                }
                return index
            },
            // 键盘向上判断可选项
            upSelectActive(index) {
                for(var i=index-1;i>-1;i--){
                    if(this.goodsIdSet.indexOf(this.chooseGoodsList[i].goodId)==-1){ // 可选
                        return i
                    }
                }
                return index
            },
            onListBlur(index) {
                $('.goods_table_select_goods_list_item').eq(index).removeClass('active')
            },
            // 监听商品表格下的input[name=productName]输入
            onTableInput(index) {
                let _nowTime = + new Date()
                if (_nowTime - this._lastTime > 100 || !this._lastTime) {
                    // 模糊查询商品列表
                    var $el = $('#goodsTable tbody tr').eq(index).find('input[name=productName]')
                    this.getGoodsListMore($el.val())
                    this._lastTime = _nowTime
                }
            },
            // 选择商品，回显表格
            onClickTableRender(index) {
                var list = this.chooseGoodsList[index]
                if(this.goodsIdSet.indexOf(list.goodId)!==-1){ // 禁止选择
                    return
                }
                list.modifyprice = list.price
                list.count = 1
                this.$set(this.goodsIdSetList, this.goodsIdSetList.length-1, list); // 把选中的商品放入列表中
                this.goodsIdSet.push(list.goodId)

                // 更新这一行的数据
                this.$set(this.tableData, this.tableData.length-1,{
                    productName: list.productName, // 商品名称
                    mainImage: list.mainImage, // 商品图片
                    skuName: list.skuName, // 规格
                    unitName: list.unitName, // 单位
                    price: list.price, // 单价（可编辑）
                    count: 1, // 数量（可编辑）
                    total: list.price * 1, // 小计
                })
                this.ontableAdd() // 添加一条
                this.getTotal() // 计算合计
            },
            // 修改数量
            onBlurFun(index) {
                if(!this.goodsIdSetList[index]){
                    return
                }
                var item = this.tableData[index]

                var value = item.count
                if(!value){
                    value = 1
                }
                if(this.goodsIdSetList[index].unitDecimalStatus == 1){ // 允许输入小数
                    var reg = /^((0|[1-9]\d{0,})((\.[0-9]{1,2})?))$/;
                    if(!reg.test(value)) {
                        layer.msg('当前商品数量格式有误')
                        value = this.goodsIdSetList[index].count
                    }

                }else{ // 不允许输入小数
                    var regex = /^(0|[1-9][0-9]*)$/;
                    if(!regex.test(value)) {
                        layer.msg('当前商品数量只能为整数')
                        value = this.goodsIdSetList[index].count
                    }
                }

                this.goodsIdSetList[index].count = value
                item.count = value
                item.total = Math.round(item.price * value * 100 ) / 100
                this.$set(this.tableData, index, item)
                this.getTotal() // 计算合计
            },
            // 计算合计
            getTotal() {
                var orderTotalMoney = 0
                var orderTotalCount = 0
                for(var i=0;i<this.goodsIdSetList.length;i++){
                    if(this.goodsIdSetList[i]){
                        orderTotalCount += Number(this.goodsIdSetList[i].count)
                        if(this.goodsIdSetList[i].count){
                            orderTotalMoney += Number(this.goodsIdSetList[i].modifyprice) * Number(this.goodsIdSetList[i].count)
                        }
                    }
                }
                $('.table_count_total').html('总数：<span style="color: #fbaf7e">'+orderTotalCount+'</span></div>')
                $('.goods_table_total').html('合计：<span style="color: #fbaf7e">￥'+orderTotalMoney.toFixed(2)+'</span>')
            },
            // 修改单价
            onBlurPrice(index) {
                if(!this.goodsIdSetList[index]){
                    return
                }
                var item = this.tableData[index]

                var value = item.price
                if(!value){
                    value = this.goodsIdSetList[index].price
                }
                
                this.goodsIdSetList[index].modifyprice = value
                item.price = value
                item.total = Math.round(item.count * value * 100 ) / 100
                this.$set(this.tableData, index, item)
                this.getTotal() // 计算合计
            },
            // 更新选中商品表格数据
            myRenderGoodsTable(list){
                console.log(list)
                for(var i=0;i<list.length;i++){
                    list[i].count = 1
                    list[i].modifyprice = list[i].price
                    this.$set(this.goodsIdSetList, this.goodsIdSetList.length-1, list[i]) // 把选中的商品放入列表中
                    this.goodsIdSet.push(list[i].goodId)
                    // 更新这一行的数据
                    this.$set(this.tableData, this.tableData.length-1,{
                        productName: list[i].productName, // 商品名称
                        mainImage: list[i].mainImage, // 商品图片
                        skuName: list[i].skuName, // 规格
                        price: list[i].price, // 单价
                        unitName: list[i].unitName, // 单位
                        count: 1, // 数量（可编辑）
                        total: list[i].price * 1, // 小计
                    })
                    this.ontableAdd() // 添加一条
                }
                this.getTotal() // 计算合计
            }
        }
    })
</script>
</body>
</html>